package com.dhcc.cdc.sys.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.sys.dao.DictypeMapper;
import com.dhcc.cdc.sys.entity.CdcProductEntity;
import com.dhcc.cdc.sys.entity.DictypeEntity;
import com.dhcc.cdc.sys.service.ICdcProductService;
import com.dhcc.cdc.sys.service.IDictypeService;
import com.dhcc.core.framework.base.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 系统字典类型表数据服务层接口
 * 
 * @ClassName: DictypeServiceImpl
 * @Description: TODO
 * @author jumper
 * @date 2021-04-16 17:11:56
 */
@Service("dictypeService")
public class DictypeServiceImpl extends BaseServiceImpl<DictypeMapper, DictypeEntity> implements IDictypeService {

    @Autowired
    ICdcProductService productSrv;

	@Override
	public List<DictypeEntity> page(Page<DictypeEntity> page, Map<String, Object> map) {
        String productCode=(String) map.get("productCode");
        if(productCode != null){
            String productId = String.valueOf(getProductId(productCode));
            if(productId != null) map.put("productId", productId);
        }
		return this.baseMapper.page(page, map);
	}
	@Override
	public List<DictypeEntity> list(Map<String, Object> map) {
        String productCode=(String) map.get("productCode");
        if(productCode != null){
            String productId = String.valueOf(getProductId(productCode));
            if(productId != null) map.put("productId", productId);
        }
		return this.baseMapper.list(map);
	}
    @Override
    public Long getProductId(String productCode) {
        Long productId=null;
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("code", productCode);
        CdcProductEntity product = this.productSrv.list(map).get(0);
        if(product != null){
            productId=product.getId();
        }

        return productId;
    }


}